//引入ajax 获取表单   阻止表单提交  像后端发送请求 

import ajax from '../../utils/ajax'
const form = document.forms[0]

form.onsubmit = function (e) {
    e.preventDefault();
    ajax('post', '/api/login', { username: form.username.value, password: form.password.value }).then((result) => {
        // alert(result.msg)
        // localStorage.setItem('token', result.data.token)
        if (result.flag) {
            localStorage.setItem('token', result.data.token)
            alert('登陆成功');
            location.replace('./index.html');

        } else {
            alert('登陆失败')
            form.username.select();
        }
    })
}










// import ajax from '../../utils/ajax'
// const form = document.forms[0]


// form.onsubmit = function (e) {
//     e.preventDefault();
//     ajax('post', '/api/login', {
//         username: form.username.value,
//         password: form.password.value
//     }).then((result) => {
//         alert(result.msg);
//         localStorage.setItem('token', result.data.token)
//     })
// }
